package ca.kooki.codesnippet.core;


public class User {

  
  //```````````````````````
  // STATIC VARIABLES
  //```````````````````````

  public static final User ANNONYMOUS = new User("-2","annonymous");
  
  //```````````````````````
  // MEMBER VARIABLES
  //```````````````````````
  
  private String _name;
  private Identifier _id;
  
  //```````````````````````
  // CONSTRUCTOR
  //```````````````````````

  public User(String id, String name)
  {
    init(id,name);
  }
  
  public User(String name) {
    init(null,name);
  }

  public User()
  {
    init(null,"");
  }
  
  private void init(String id, String name)
  {
    _name = name;
    _id = new Identifier(this.getClass());
    
    if (id != null)
    {
      _id.setId(id);
    }
    
  }
  
  //```````````````````````
  // INTERFACE
  //```````````````````````
  
  public boolean isOfficial()
  {
    return _id.isOfficial();
  }
  
  public String getId()
  {
    return _id.getId();
  }
  
  public  void setId(String newId)
  {
    _id.setId(newId);
  }
  
  public String getName()
  {
    return _name;
  }
  
  public String toString()
  {
    return _name;
  }
  
  public boolean equals(Object obj)
  {
    if (obj == null || !User.class.equals(obj.getClass()))
    {
      return false;
    }
    
    User compareTo = (User)obj;
    
    if (_id.isOfficial() && _id.equals(compareTo._id))
    {
      return true;
    }
    
    if (!_id.equals(compareTo._id))
    {
      return false;
    }
    
    if (!_name.equals(compareTo._name))
    {
      return false;
    }
    
    return true;
  }
  
  public int hashCode()
  {
    return _name.hashCode();
  }

}
